//
//  IAPProduct.swift
//  GhostWorld
//
//  Created by Kam on 2018/6/7.
//  Copyright © 2018 LKGood. All rights reserved.
//

import Foundation
import CoreData

private let entityName = CoreDataEntityName.iapIdentifier.rawValue
private let context = CoreDataHelper.getContext()

extension IAPProduct {
  static func getAll() -> [String]? {
    let request = NSFetchRequest<IAPProduct>()
    let entity = NSEntityDescription.entity(forEntityName: entityName, in: context)
    request.entity = entity
    
    do {
      let iaps = try context.fetch(request)
      return iaps.map { $0.product! }
    } catch let error {
      loggingPrint(error)
      return nil
    }
  }
}
